package com.googlesource.gerrit.plugins.examples.servlet;

import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.urswolfer.gerrit.client.rest.GerritAuthData;
import com.urswolfer.gerrit.client.rest.GerritRestApiFactory;

import java.util.List;

/**
 * @author zxs
 * @date 2022/5/20
 */
public class RestApiClientUtil {

    private String host;

    private static GerritApi getApi() {
        GerritRestApiFactory factory = new GerritRestApiFactory();
        GerritAuthData.Basic authData = new GerritAuthData.Basic(
                "http://192.168.18.162:1998",
                "gerrit",
                "gerrit",true);
        GerritApi gerritApi = factory.create(authData);
        return gerritApi;
    }

    public static List<AccountInfo> getSuggestAccounts() throws RestApiException {
        GerritApi gerritApi = getApi();
        List<AccountInfo> accountInfos = gerritApi.accounts().suggestAccounts("z").get();
        return accountInfos;
    }

}
